package com.example.exam.service.impl;

import com.example.exam.dao.RoleDao;
import com.example.exam.entity.Role;
import com.example.exam.service.RoleService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * (Role)表服务实现类
 *
 * @author makejava
 * @since 2021-09-04 15:02:45
 */
@Service("roleService")
public class RoleServiceImpl implements RoleService {
    @Resource
    private RoleDao roleDao;

    /**
     * 通过ID查询单条数据
     *
     * @param roleId 主键
     * @return 实例对象
     */
    @Override
    public Role queryById(Integer roleId) {
        return this.roleDao.queryById(roleId);
    }

    /**
     * 查询多条数据
     *
     * @param offset 查询起始位置
     * @param limit  查询条数
     * @return 对象列表
     */
    @Override
    public List<Role> queryAllByLimit(int offset, int limit) {
        return this.roleDao.queryAllByLimit(offset, limit);
    }

    /**
     * 新增数据
     *
     * @param role 实例对象
     * @return 实例对象
     */
    @Override
    public Role insert(Role role) {
        this.roleDao.insert(role);
        return role;
    }

    /**
     * 修改数据
     *
     * @param role 实例对象
     * @return 实例对象
     */
    @Override
    public Role update(Role role) {
        this.roleDao.update(role);
        return this.queryById(role.getroleId());
    }

    /**
     * 通过主键删除数据
     *
     * @param roleId 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer roleId) {
        return this.roleDao.deleteById(roleId) > 0;
    }

    @Override
    public List<Role> queryByAll() {
        return this.roleDao.queryAll2();
    }

    @Override
    public Role queryByIdAndName(String roleName, String password) {
        return this.roleDao.queryByIdAndName(roleName, password);
    }

    //姚贾涛
    @Override
    public List<Role> selectAll2(Integer page, Integer limit, String roleName) {
        List<Role> roles = roleDao.selectAll2((page - 1) * page, limit, roleName);
        return roles;
    }

    public boolean update2(Role role) {
        return roleDao.update2(role);
    }

    public boolean delete2(int[] bids) {
        return roleDao.delete2(bids);
    }

    @Override
    public int getroleCount2(String roleName) {
        return roleDao.getroleCount2(roleName);
    }

    public Role queryByIdAndName2(String username, String password) {
        return roleDao.queryByIdAndName2(username, password);
    }

    @Override
    public int insert2(Role role) {
        return roleDao.insert2(role);
    }
}